package com.example.demo.dao.db2;

import com.example.demo.entity.ArcheryUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author ggkt
 * @date 2021/1/4 13:43
 */
public interface ArcheryDao {
    @Select("select * from sql_users")
    List<ArcheryUser> userList() throws Exception;

    @Insert("insert into sql_users(id,password,is_superuser,username,first_name,last_name," +
            "email,is_staff,is_active,date_joined,display,ding_user_id,wx_user_id,feishu_open_id,failed_login_count) " +
            "values(#{id},#{password},#{isSuperuser},#{userName},#{firstName},#{lastName}," +
            "#{email},#{isStaff},#{isActive},#{dateJoined},#{display},#{dingUserId},#{wxUserId},#{feishuOpenId},#{failedLoginCount})")
    int insertUser(ArcheryUser aUser) throws Exception;


    /**
     * create the relationship of group;
     * @param userId
     * @param groupId
     * @return
     * @throws Exception
     */
    @Insert("insert into sql_users_groups(users_id,group_id) values(#{userId},#{groupId})")
    int insertUGroup(int userId,int groupId)throws Exception;

    /**
     * create the relationship of Resource;
     * @param userId
     * @param groupId
     * @return
     * @throws Exception
     */
    @Insert("insert into sql_users_resource_group(users_id,resourcegroup_id) values(#{userId},#{groupId})")
    int insertRGroup(int userId,int groupId)throws Exception;

    /**
     * update records which user has left the company;
     * @param userId
     * @return
     * @throws Exception
     */
    @Update("update sql_users  set is_staff = 0,is_active= 0 where id =#{userId}")
    int updateUser(int userId)throws Exception;

    @Update("update sql_users  set ding_user_id = #{dingId} where username =#{username}")
    int updateDingUser(String dingId,String username)throws Exception;
}
